program mystacker;
const max=100;
type StackType = object
                Stackdata:array [1..max] of Integer;
                Top:Integer;
                procedure push (value:Integer);
                function pop:Integer;
                function Empty:Boolean;
                procedure Init;
                end;


procedure StackType.Push (Value:Integer);
begin
If top=max then Writeln('Stack is FULL!')
else    begin
        top:=top+1;
        stackdata[top]:=value;
        end;
end;

function StackType.Pop:integer;
begin
if top=0 then writeln('Stack is EMPTY!')
else    begin
        pop:=stackdata[top];
        top:=top-1;
        end;
end;

function Stacktype.Empty:boolean;
begin
empty:= top=0;
end;

procedure StackType.Init;
begin
top:=0;
end;

var Mydata:StackType;
value:integer;

begin
Mydata.init;

Writeln('Write a sequence od numbers other than 0');

read(value);
while value <> 0 do
begin
if value > 0 then
                        begin
                        Mydata.push(value);
                        read(value);
                        end
              else
                        begin
                        writeln('Wanted value:');
                        writeln(Mydata.pop);
                        read(value);
                        end;
end;
end.

